// var A = (function () {
//     console.log('class A was created');
// }());

//以上代码等于下面的例子
// var B = function () {
//     console.log('class B was created');
// };
// B();

// var B2 = () => {
//     console.log('class B2 was created');
// };
// B2();

var C = (function () {
    console.log('function was created');

    function C() {
        console.log('function C run');
    }

    C.init = function () {
        console.log('init...');
        var name = 'Sinya';
        var works = [];

        return {
            getUserName: function () {
                works.push('Testing');
                works.push('Coding');
                console.log('function getUserName run');
                console.log('getUserName: ', name);
                return this;
            },

            printName: function () {
                console.log('function printName run');
                console.log('print user name: ', name);
            },
        };
    };

    return C;
}());


/**
 * 解读
 * 1. 创建一个函数，并且立即调用，这个匿名函数有返回值C
 * 2. 而C是一个内部函数，实际上表示一个类class
 * 3. 匿名函数内部对这个C对象增加一个init参数，类型是函数，但是函数本身又是返回值class类型
 * 4. return C，外部的var C 就相当于创建并声明了一个对象，对象内部设置了 有返回值的init函数
 */
